# 后台用户控制器
class Admin::UsersController < Admin::BaseController

  # 用户首页
  def index
    @users = User.all
  end

  # 新建用户页面
  def new
    @user = User.new
  end

  # 新增用户
  def create
    @user = User.new(user_params)
    if @user.save
      redirect_to admin_users_path
    else
      render 'new'
    end
  end

  # 编辑用户页面
  def edit
    @user = User.find(params[:id])
  end

  # 更新用户信息
  def update
    @user = User.find(params[:id])
    if @user.update_attributes(user_params)
      redirect_to admin_users_path
    else
      render 'edit'
    end
  end

  # 删除用户信息
  def destroy
    User.find(params[:id]).destroy
    redirect_to admin_users_path
  end

  private

  def user_params
    params.require(:user).permit(:name, :password, :password_confirmation, :note)
  end
end
